var buttonState = "1";

var name = "";
var eamineeId = "";

var payType = "";
$(document).ready(function(){
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getOrdersByStudentId",
		async:false,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			payType = result.extend.code;
		}
	});
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getStudentById",
		async:true,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			
			var promiseType = result.extend.student.promiseType;
			if(promiseType==1 && payType==1)
				window.location.href = "affirmMess.html";
			
			name = result.extend.student.name;
			eamineeId = result.extend.student.eamineeId;
			
			var cardId = result.extend.student.cardId;
			var graduationType = result.extend.student.graduationType;
			var examineeType = result.extend.student.examineeType;
			
			document.getElementById("cardId").innerHTML = cardId;
			switch (graduationType)
			{
				case 1:
					document.getElementById("graduationType").innerHTML = '高中';
					break;
				case 2:
					document.getElementById("graduationType").innerHTML = '中等师范';
					break;
				case 3:
					document.getElementById("graduationType").innerHTML = '中等专业学校';
					break;
				case 4:
					document.getElementById("graduationType").innerHTML = '职业高中学校';
					break;
				case 5:
					document.getElementById("graduationType").innerHTML = '技工学校';
					break;
			}
			switch (examineeType)
			{
				case 1:
					document.getElementById("examineeType").innerHTML = '城市应届';
					break;
				case 2:
					document.getElementById("examineeType").innerHTML = '农村应届';
					break;
				case 3:
					document.getElementById("examineeType").innerHTML = '城市往届';
					break;
				case 4:
					document.getElementById("examineeType").innerHTML = '农村往届';
					break;
			}
			
			/*var promiseType = result.extend.student.promiseType;
			
			if(promiseType == 1)
			{
				document.getElementById("promiseType").checked = true;
				document.getElementById("agree").innerHTML = '已同意';
			}*/
			
			document.getElementById("name").innerHTML = name;
		}
	});
	
	var promiseTime = new Date().getFullYear()+"年"+(new Date().getMonth()+1)+"月"+new Date().getDate()+"日";
	document.getElementById("promiseTime").innerHTML = promiseTime;
});

function changeCheckbox()
{
	var promiseType = document.getElementById("promiseType");
	if(promiseType.checked)
	{
		document.getElementById("agree").innerHTML = '已同意';
	}
	else
	{
		document.getElementById("agree").innerHTML = '';
	}
}

function ok()
{
	if(buttonState == "1")
	{
		buttonState = "0";
		
		var promiseType = document.getElementById("promiseType");
		if(promiseType.checked)
			passByValue();
		else
			{alert("请勾选同意");buttonState = "1";}
	}
}

function passByValue()
{
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/updateStudent",
		async:true,
		data:{
			id:student_id,
			promiseType:1
		},
		success:function(result)
		{
			buttonState = "1";
			if(result.code == 100)
			{
				$.ajax({
					type:'GET',
					cache:false,
					url:rootPath+"/weixinpay",
					async:true,
					data:{
						id:student_id,
						name:name,
						eamineeId:eamineeId
					},
					success:function(result)
					{
						if(result.code == 100)
						{
							var out_trade_no = result.extend.returnMap.out_trade_no;
							var code_url = result.extend.returnMap.code_url;
							var body1 = result.extend.returnMap.body;

							window.sessionStorage.setItem("out_trade_no", out_trade_no);
							window.sessionStorage.setItem("code_url", code_url);
							window.sessionStorage.setItem("body1", body1);

							window.location.href = "payTheFees.html";
						}
						else
						{
							alert(result.extend.msg);
						}
					},
					error: function(){buttonState = "1";}
				});
			}
			else
			{
				alert(result.extend.code);
			}
		},
		error: function(){buttonState = "1";}
	});
}